<template>
  <div class="dashboard-container">
    <div class="dashboard-text">
      <el-card class="tree-card">
        <!-- 用了一个行列布局 -->
        <treeTools :node-data="{name:'江苏传智播客教育科技股份有限公司', manager: '负责人',id:''}" :is-root="true" @add="adddept" />
        <hr>
        <el-tree :data="treedata" default-expand-all :expand-on-click-node="false">
          <template #default="obj">
            <treeTools :node-data="obj.data" :is-root="false" @edit="editDepartment" @add="adddept" @del="depts" />
          </template>
        </el-tree>
      </el-card>
    </div>
    <adddepts ref="addbanj" :dialog-visible.sync="dialogVisible" :node-data="current" @add="depts" />
  </div>
</template>

<script>
import adddepts from './components/adddepts.vue'
import treeTools from './components/tabal.vue'
import { department } from '@/api/departments'
import { islist } from '@/utils/index'
export default {
  components: { treeTools, adddepts },
  data() {
    return {
      treedata: [],
      dialogVisible: false,
      current: {}
    }
  },
  async created() {
    this.depts()
  },
  methods: {
    adddept(nodeData) {
      this.dialogVisible = true
      this.current = nodeData
    },
    async depts() {
      const { depts } = await department()
      this.treedata = islist(depts, '')
    },
    editDepartment(val) {
      this.dialogVisible = true
      this.current = val
      this.$refs.addbanj.getDepartmentDetail(val)
    }
  }

}
</script>

<style lang="scss" scoped>
.tree-card {
  padding: 30px  140px;
  font-size:14px;
}
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
